<template>
  <div>
    <el-form class="input-form"
             label-position="right"
             label-width="120px"
             ref="editForm"
             :rules="propRules"
             :disabled="propReadonly"
             :model="form"
    >
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="父级库位" prop="parentId">
            <el-input disabled :value="viewData.parentName" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="库位编码" prop="code">
            <el-input v-model="form.code" placeholder="自动生成" disabled/>
          </el-form-item>
        </el-col>

      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="库位名称" prop="name">
            <el-input v-model="form.name"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="所在仓库" prop="warehouseId">
            <el-select v-model="form.warehouseId" filterable :disabled="strings.isNotBlank(viewData.warehouseId)">
              <el-option value="">请选择</el-option>
              <el-option v-for="dict in propDictionaries['warehouseId']" :key="dict.id" :label="dict.name"
                         :value="dict.id"/>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="库位全称" prop="fullname">
            <el-input v-model="form.fullname"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="默认库位" prop="flagDefault">
            <el-switch v-model="form.flagDefault" active-color="#13ce66"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>

export default {
  data() {
    return {
      form: {},
      viewData: {}
    }
  },
  methods: {},
  created() {
    this.$emit('event-register', {
      validate: (callback) => {
        this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData, initData) => {
        this.form = global.utils.jsonClone(formData)
        this.viewData = this.propCurrentRow
        // 新增时需要填写父级机构的id和名称
        if (!this.form.id && initData) {
          this.$set(this.viewData, 'parentId', initData.id)
          this.$set(this.viewData, 'parentName', initData.label)
          this.$set(this.viewData, 'warehouseId', initData.meta ? initData.meta.warehouseId : null)
          this.$set(this.form, 'parentId', initData.id)
          this.$set(this.form, 'warehouseId', initData.meta ? initData.meta.warehouseId : null)
        }
        // 设置switch 元素默认值
        this.$set(this.form, 'flagDefault', this.form.flagDefault == undefined ? false : this.form.flagDefault)
      },
      afterSave: () => {
      },
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {
      },
      beforeFlow: (flowButtonKey) => {
        return true
      },
      afterFlow: (flowButtonKey) => {
      },
      beforeClose: () => {
        return true
      }
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object
  },
  components: {},
  computed: {}
}
</script>

<style lang="scss" scoped>
  .container {
    width: 100%;
    height: 100%;
  }
</style>
